package com.example.accountkeeping.UI.Fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import android.sax.Element;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.example.accountkeeping.R;
import com.google.android.material.floatingactionbutton.FloatingActionButton;

import mehdi.sakout.aboutpage.AboutPage;

/**
 * @Description: 关于页面
 */
public class AboutFragment extends Fragment {

    public FragmentActivity activity;

    //悬浮按钮
    private FloatingActionButton fab;
    //滑动菜单
    private DrawerLayout drawerLayout;
    //菜单按钮
    private Button menuButton;

    private RelativeLayout relativeLayout;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        activity = getActivity();
        View view = inflater.inflate(R.layout.fragment_about, container, false);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        //用Toolbar替换ActionBar
        setHasOptionsMenu(true);
        AppCompatActivity appCompatActivity= (AppCompatActivity) getActivity();
        Toolbar toolbar=  appCompatActivity.findViewById(R.id.fragment_about_toolbar);
        toolbar.setTitle("");
        appCompatActivity.setSupportActionBar(toolbar);

        //菜单按钮打开滑动窗口
        menuButton = activity.findViewById(R.id.fragment_about_btn_menu);
        drawerLayout = activity.findViewById(R.id.drawer_layout);
        menuButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                drawerLayout.openDrawer(GravityCompat.START);//打开滑动菜单
            }
        });

        relativeLayout= activity.findViewById(R.id.fragment_about_relative_layout);

        View aboutPage = new AboutPage(activity)
                .isRTL(false)
                .setImage(R.drawable.nav_self)//图片
                .setDescription("记账本期末大作业！")//介绍
                .addGroup("19信安李芷靖")
                .addGroup("邮箱")
                .addEmail("zibengli@163.com")//邮箱
                .addGroup("gitee仓库")
                .addWebsite("https://gitee.com/zibengli/AccountKeeping.git")//gitee仓库
                .addGroup("这是一款贴心的记账软件，一切以方便为落脚点出发，没有冗余的功能。看似简单的操作背后，却能通过扇形图功能，" +
                        "帮您分析消费状况，让你对自己的消费功能做出改善。记账虽然不能帮你实现你的财富自由，但我相信，只要你坚持记账" +
                        "不断改善自己的消费情况，积极开源节流，一定能够实现财富自由！")
                .create();

        relativeLayout.addView(aboutPage);
    }
}
